package com.example.demovote.controller;


import com.example.demovote.entity.User;
import com.example.demovote.service.IRecordService;
import com.example.demovote.service.ServiceException;
import com.example.demovote.vo.Result;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.SessionAttribute;

import javax.annotation.Resource;

/**
 * <p>
 * 投票系统-投票记录表-6 前端控制器
 * </p>
 *
 * @author ly
 * @since 2024-03-18
 */
@RestController
@RequestMapping("/demovote/record")
public class RecordController {

    @Resource
    IRecordService recordService;

    @RequestMapping("commit")
    public Result commit(int vid, int[] iids,
                         @SessionAttribute User loginedUser){
        try {
            recordService.commit(vid,loginedUser.getId(), iids);
            return new Result(1, "投票成功",null);
        } catch (ServiceException e) {
            return new Result(e.getCode(),e.getMessage(),null);
        }
    }

}

